home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Wipes ƒ / Spiral wipe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-09  |  3.2 KB  |  118 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Spiral wipe.c
  4.  
  5. Purpose:    Graphic effect from offscreen bitmap to main window (on
  6.             screen).  See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define CorrectTime 1
  32. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  33. #define theWindowWidth (boundsRect.right-boundsRect.left)
  34.  
  35. pascal short SpiralGyra(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  36.  
  37. /* Start in the topleft corner, facing downwards.  Copy until you hit (a) the
  38.    edge of the screen, or (b) bits you've already copied.  Then turn counter-
  39.    clockwise and do it again.  */
  40.    
  41. pascal short SpiralGyra(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  42. {
  43.     int                stop,sbottom,sleft,sright,iterrow,itercol,direction;
  44.     Rect            source;
  45.     Boolean            everyOther;
  46.     int                BOXSIZE;
  47.     RgnHandle        boundsRgn;
  48.     
  49.     boundsRgn=NewRgn();
  50.     SetRectRgn(boundsRgn, boundsRect.left, boundsRect.top, boundsRect.right, boundsRect.bottom);
  51.     BOXSIZE=theWindowHeight/15;
  52.     everyOther=FALSE;
  53.     stop=0;
  54.     sbottom=theWindowHeight/BOXSIZE-(theWindowHeight%BOXSIZE ? 0 : 1);
  55.     sleft=0;
  56.     sright=theWindowWidth/BOXSIZE-(theWindowWidth%BOXSIZE ? 0 : 1);
  57.     direction=3;
  58.     iterrow=stop;
  59.     itercol=sleft;
  60.     while ((stop<=sbottom)&&(sleft<=sright))
  61.     {
  62.         StartTiming();
  63.         source.top=iterrow*BOXSIZE;
  64.         source.bottom=source.top+BOXSIZE;
  65.         source.left=itercol*BOXSIZE;
  66.         source.right=source.left+BOXSIZE;
  67.         OffsetRect(&source, boundsRect.left, boundsRect.top);
  68.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  69.             &source, &source, 0, boundsRgn);
  70.         switch (direction)
  71.         {
  72.             case 0:  /* facing right */
  73.                 if (itercol==sright)
  74.                 {
  75.                     sbottom--;
  76.                     direction++;
  77.                     iterrow--;
  78.                 }
  79.                 else itercol++;
  80.                 break;
  81.             case 1:  /* facing up */
  82.                 if (iterrow==stop)   /* that reads "s top," not "stop" */
  83.                 {
  84.                     sright--;
  85.                     direction++;
  86.                     itercol--;
  87.                 }
  88.                 else iterrow--;
  89.                 break;
  90.             case 2:  /* facing left */
  91.                 if (itercol==sleft)
  92.                 {
  93.                     stop++;
  94.                     direction++;
  95.                     iterrow++;
  96.                 }
  97.                 else itercol--;
  98.                 break;
  99.             case 3:  /* facing down */
  100.                 if (iterrow==sbottom)
  101.                 {
  102.                     sleft++;
  103.                     direction=0;
  104.                     itercol++;
  105.                 }
  106.                 else iterrow++;
  107.                 break;
  108.         }
  109.         if (everyOther)
  110.             TimeCorrection(CorrectTime);
  111.         everyOther=!everyOther;
  112.     }
  113.     
  114.     DisposeRgn(boundsRgn);
  115.     
  116.     return 0;
  117. }
  118.